const processBox = document.querySelector("#processBox");//运算过程
const results = document.querySelector("#results");//结果
const buttons = document.querySelectorAll("button");
const operateBtn = document.getElementsByClassName("operateBtn");
// 结果
let resultsBox = document.getElementById('results');
let resultStr = localStorage.getItem('result');
resultsBox.innerText = JSON.parse(resultStr);
// 过程
let processDom = document.getElementById('processBox');
let processStr = localStorage.getItem('process');
processDom.innerText = JSON.parse(processStr)
;
buttons.forEach((item) => {
  item.onclick = () => {
    if (item.id == "clearBtn") {
      processBox.innerText = "";
      results.innerText = "";
    } else if (item.id == "delBtn") {
      let string = processBox.innerText.toString();
      processBox.innerText = string.substr(0, string.length - 1);
    } else if (processBox.innerText != '' && item.id == 'equalBtn') {
      results.innerText = (eval(processBox.innerText)).toFixed(2);
    } else if (processBox.innerText == '' && item.id == 'equalBtn') {
      results.innerText = 'empty';
      setTimeout(() => (results.innerText = ''), 1000);
    } else if (processBox.innerText == '' && (item.id == '+' || item.id == '-' || item.id == '/' || item.id == '*')) {
      processBox.innerText = '';
    } else {
      processBox.innerText += item.id;
    }
  }
});
let webStorage = document.getElementById('equalBtn');
webStorage.addEventListener('click', function webStorage() {
  // results框
  let keyValRes = document.getElementById('results');
  localStorage.setItem("result", JSON.stringify(keyValRes.innerText));
  // processBox
  let keyValProc = document.getElementById('processBox');
  localStorage.setItem("process", JSON.stringify(keyValProc.innerText));

}
);
